package com.richdown.movie.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

public class MapUtil {
	/**
	 * string转map，如将get方式的url转成map
	 * @param param 要转成map的string
	 * @param divideString 分割param的分隔符
	 * @param divideKeyValue 分割divideString分隔后的parma的分隔符，用了分隔map的key与value
	 * @param startString param中有效子串的开始字符
	 * @return
	 */
	public static Map String2Map(String param,String divideString,String divideKeyValue,String startString){
		if(StringUtils.isNotBlank(startString))
			param=param.substring(param.indexOf(startString)+1, param.length());
		String [] params=param.split(divideString);
		Map map=new HashMap();
		for(int i=0;i<params.length;i++){
			if(params[i].indexOf(divideKeyValue)<=0)
				continue;
			else{
				String[] a=params[i].split(divideKeyValue);
				if(a.length==2)
					map.put(a[0], a[1]);
				else
					map.put(a[0], null);
			}
		}
		return map;
	}
	public static void main(String[] args) {
		String a="https://ipos.10086.cn/ips/cmpayService?characterSet=00&callbackUrl=http://localhost/test1.aspx&notifyUrl=http://localhost/test.aspx&ipAddress=0.0.0.0&merchantId=888073157340001&requestId=1348452975359&signType=MD5&type=GWDirectPay&version=2.0.0&amount=10&bankAbbr=ICBC&currency=00&orderDate=2012-09-24 02:16:15&orderId=201209241348452975359&merAcDate=0001-01-01 00:00:00&period=7&periodUnit=02&merchantAbbr=飞信&productDesc=&productId=1348452975359&productName=TestProduct&productNum=1&reserved1=&reserved2=&userToken=&showUrl=&couponsFlag=00&hmac=e2eb1e6eeb5d1a12248fc91bd0a3f53d";
//		a=a.substring(a.indexOf("?")+1, a.length());
		Map m=MapUtil.String2Map(a, "&", "=","?");
	}
}
